import React from 'react'
import axios from 'axios'

class App extends React.Component {
  getStudentData = () => {
    axios.get('http://localhost:3000/api1/students').then(
      response => {
        console.log('成功了', response.data)
      },
      error => {
        console.error(error)
      }
    )
  }

  getCarData = () => {
    axios.get('http://localhost:3000/api2/cars').then(
      response => {
        console.log('成功了', response.data)
      },
      error => {
        console.error(error)
      }
    )
  }

  render() {
    return (
      <div>
        <button style={{ margin: '20px' }} onClick={this.getStudentData}>
          点我获取学生数据
        </button>
        <button style={{ margin: '20px' }} onClick={this.getCarData}>
          点我获取汽车数据
        </button>
      </div>
    )
  }
}

export default App
